package com.myStruts.util;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

import com.myStruts.fromBean.BaseBean;

public class FullBean {

	public FullBean() {
	}
	public static BaseBean full(String className,HttpServletRequest request) throws Exception{
		Class clazz=Class.forName(className);
		BaseBean bean=(BaseBean)clazz.newInstance();
		Field[] fields=clazz.getDeclaredFields();
		for (Field each : fields) {
			each.setAccessible(true);
			String type = each.getType().toString();//得到此属性的类型  
			String value=request.getParameter(each.getName());
			if (type.endsWith("int")|| type.endsWith("Integer")) { 
	        	if(value!=null && !"".equals(value)){
	        		each.set(bean,Integer.parseInt(value));
	        	}else{
	        		each.set(bean,0);
	        	}
	        }else{
	        	each.set(bean,value);
	        }
			each.setAccessible(false);
		}
		return bean;
	}
	

}
